package com.pet.server.ext.action.user;

import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.BeanToJson;
import com.pet.server.ext.Result;
import com.pet.server.ext.data.PetAdopt;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.cache.ConstantUtil;

public class Adoptapply extends ActionBase{
	
	public String userName,password,owner;	
	public Adoptapply(){
		 needCheckAuth =true;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
	    //owner = meta.getParam("param_0");
	}
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
		List<PetAdopt> list = userService.queryPetAdoptByItemUserId(user.user_id);
		Result result = new Result();
	    JSONArray array = new JSONArray();
		for(PetAdopt adopt:list){
			JSONObject o = new JSONObject();
			o.accumulate("adopt_id", adopt.adopt_id);
			o.accumulate("image", adopt.ico_path);
			o.accumulate("breed", adopt.breed);
			o.accumulate("breed_name", ConstantUtil.getInstance().getName(adopt.breed));
			o.accumulate("sex", adopt.sex);
			array.add(o);
		}
		data.accumulate("list", array);
		result.ret.put("data", data);
	    return result;
	}
}
